package net.xdclass.config;

import com.google.code.kaptcha.Constants;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
public class KaptchaConfig {
    @Bean
    //给Bean起别名
    @Qualifier("captchaProducer")
    public DefaultKaptcha defaultKaptcha(){
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        Properties properties = new Properties();
//        properties.setProperty(Constants.KAPTCHA_BORDER,"yes");
//        properties.setProperty(Constants.KAPTCHA_BORDER_COLOR,"220,220,220");
//        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_COLOR,"38,29,12");
//        properties.setProperty(Constants.KAPTCHA_IMAGE_WIDTH,"147");
//        properties.setProperty(Constants.KAPTCHA_IMAGE_HEIGHT,"34");
//        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_SIZE,"25");
//        properties.setProperty(Constants.KAPTCHA_SESSION_KEY,"code");
        //验证码个数
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_LENGTH,"4");
        //字体间隔
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_SPACE,"8");
        //干扰线颜色
        properties.setProperty(Constants.KAPTCHA_NOISE_COLOR,"white");
        //干扰线实体类，顶层接口 NoiseProducer 目前就两个，Default默认的和NoNoise没有
        properties.setProperty(Constants.KAPTCHA_NOISE_IMPL,"com.google.code.kaptcha.impl.NoNoise");
        //图片样式，顶层接口 GimpyEngine，实现有三个 Fish鱼眼、Shadow阴影、Water水纹
        properties.setProperty(Constants.KAPTCHA_OBSCURIFICATOR_IMPL,"com.google.code.kaptcha.impl.FishEyeGimpy");
        //文字来源
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_STRING,"0123456789");
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }

}
